package zhihui.mobile.ui.myself;

import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.nostra13.universalimageloader.core.ImageLoader;

import zhihui.mobile.R;
import zhihui.mobile.bean.user.UserInfo;
import zhihui.mobile.config.Config;
import zhihui.mobile.presenter.IPresenter;
import zhihui.mobile.presenter.myself.MyselfMainPresenter;
import zhihui.mobile.presenter.shop.BaseShopPresenter;
import zhihui.mobile.ui.BaseActivity;
import zhihui.mobile.ui.login.LoginActivity;
import zhihui.mobile.ui.utils.UiFooterLayout;

/**
 * Created by 张公铭 on 2017/9/11 0011.
 */

public class MySelfMainActivity extends BaseActivity implements IMyselfMainContract.IMyselfMainView
{
    private IMyselfMainContract.IMyselfMainPresenter presenter = new MyselfMainPresenter();
    private BaseShopPresenter shopPresenter = new BaseShopPresenter();
    private ImageView iv_photo;
    private TextView tv_name;
    private TextView tv_order;
    private RelativeLayout rl_wait_pay;
    private RelativeLayout rl_wait_receiving;
    private RelativeLayout rl_over;
    private TextView tv_shop_cart;
    private TextView tv_attention;
    private TextView tv_sales;
    private TextView tv_yao;
    private TextView tv_package;
    private TextView tv_service;
    private TextView tv_phone;

    private UiFooterLayout mfooter;

    @Override
    public void initView()
    {
        iv_photo = (ImageView) findViewById(R.id.iv_myself_main_photo);
        iv_photo.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                if (!zhihui.mobile.ui.utils.UiUtils.cheeckLogin(MySelfMainActivity.this))
                {
                    return;
                }
                Intent intent = new Intent(MySelfMainActivity.this, UserSettingActivity.class);
                startActivity(intent);
            }
        });

        tv_name = (TextView) findViewById(R.id.tv_myself_main_username);
        tv_name.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                if (tv_name.getText().equals("注册/登录"))
                {
                    Intent intent = new Intent(MySelfMainActivity.this, LoginActivity.class);
                    startActivity(intent);
                }
            }
        });

        tv_order = (TextView) findViewById(R.id.tv_myself_main_order);
        tv_order.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                //订单管理
                presenter.goOrderByState(0);
            }
        });

        rl_wait_pay = (RelativeLayout) findViewById(R.id.rl_myself_main_waitpay);
        rl_wait_pay.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                //订单待付款
                presenter.goOrderByState(1);
            }
        });
        rl_wait_receiving = (RelativeLayout) findViewById(R.id.rl_myself_main_wait_receiving);
        rl_wait_receiving.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                //待收货
                presenter.goOrderByState(3);
            }
        });

        rl_over = (RelativeLayout) findViewById(R.id.rl_myself_main_over);
        rl_over.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                //已完成
                presenter.goOrderByState(4);
            }
        });

        tv_shop_cart = (TextView) findViewById(R.id.tv_myself_main_shopcart);
        tv_shop_cart.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                //购物车
                shopPresenter.goShopCart(MySelfMainActivity.this, MySelfMainActivity.this);
            }
        });

        tv_attention = (TextView) findViewById(R.id.tv_myself_main_attention);
        tv_attention.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                //关注
                presenter.goAttention();

            }
        });

        tv_sales = (TextView) findViewById(R.id.tv_myself_main_sales);
        tv_sales.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                presenter.goMySales();
            }
        });

        tv_yao = (TextView) findViewById(R.id.tv_myself_main_yao);
        tv_yao.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                showMessage("敬请期待！");
            }
        });

        tv_package = (TextView) findViewById(R.id.tv_myself_main_package);
        tv_package.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                //包裹信息
                presenter.goPackageService();
            }
        });

        tv_service = (TextView) findViewById(R.id.tv_myself_main_service);
        tv_service.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                showMessage("敬请期待！");
            }
        });

        tv_phone = (TextView) findViewById(R.id.tv_myself_main_phone);
        tv_phone.setOnClickListener(new View.OnClickListener()
        {
            @Override
            public void onClick(View v)
            {
                com.zgm.utils.UiUtils.showDialog(MySelfMainActivity.this, "客服热线", "110");
            }
        });

        mfooter = (UiFooterLayout) findViewById(R.id.myself_main_footer);
        mfooter.change(UiFooterLayout.Meun.Myself);
    }

    @Override
    protected int getLayoutResId()
    {
        return R.layout.myself_main_activity;
    }

    @Override
    protected IPresenter[] getPresenters()
    {
        return new IPresenter[]{presenter};
    }

    @Override
    protected void onInitPresenter()
    {
        presenter.init(this, this);
    }

    @Override
    public void refreshViewData(UserInfo userInfo)
    {
        if (userInfo != null)
        {
            if (!userInfo.getPic().equals("0"))
            {
                ImageLoader.getInstance().displayImage(Config.FILE_URL + userInfo.getPic(), iv_photo);
            }
            tv_name.setText(userInfo.getName().equals("") ? userInfo.getNo() : userInfo.getName());
        } else
        {
            iv_photo.setImageResource(R.drawable.use_head_portrait);
            tv_name.setText("注册/登录");
        }

    }
}
